package com.abc.model;

import java.util.*;

public class ReportRepository {
	
	private int id = 0;
	
	private Map<String, Project> projects = new HashMap<String, Project>();

	public void addProject(Project newProject) {
		id++;
		projects.put(""+id, newProject);
	}

	public Map<String, Project> getProjects() {
		return projects;
	}

	public double[] getAllEffortsForEmployee(String devName)
	{
		
		List<Double> effortsForProj = new ArrayList<Double>();
		
		Set<String> allProjects = projects.keySet();
		for(String proj : allProjects){
			Project project = this.projects.get(proj);
			effortsForProj.add(project.getAllEffort(devName));
		}
		
		double[] efforts = new double[effortsForProj.size()];
		for(int i = 0; i < effortsForProj.size(); i++){
			
			efforts[i] = (double) effortsForProj.get(i);
		}
		
		//double[] a = new double[10]; //effortsForProj.toArray(new Double[effortsForProj.size()] ) //effortsForProj.toArray() ;
		return efforts;
	}
	
	public Set<String> getYears() {
		Set<String> years = new HashSet<String>();
		Collection<Project> projects = getProjects().values();
		for(Project proj : projects) {
			Collection<ProjectYear> yearsInP = proj.getProjectYears().values();
			for(ProjectYear yProj : yearsInP) {
				years.add(yProj.getYear());
			}
		}
		return years;
	}
	
	
	public Set<String> getDevNames() {
		Set<String> names = new HashSet<String>();
		Collection<Project> projects = getProjects().values();
		for(Project proj : projects) {
			names.addAll(proj.getDevNames());
		}
		return names;
	}
		
}


